package com.example.springbootwebdemo.repository;

import com.example.springbootwebdemo.entity.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * select * 在实际开发中不推荐使用
 */
public interface ProductRepository {
    @Select("select id,name,description,price,pic from product where uid=(select id from user where username=#{username})")
    List<Product> findByUsername(String username);

    @Delete("delete from product where id=#{id}")
    int deleteById(int id);

    @Select("select id,name,description,price,pic from product where id=#{id}")
    Product findById(Integer id);

    @Update("update product set name=#{product.name},description=#{product.description},price=#{product.price},pic=#{product.pic} where id=#{product.id}")
    int update(@Param("product") Product product);

    @Select("select id,name,description,price,pic from product where uid=#{uid}")
    List<Product> findByUid(Integer uid);
}
